<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <button class="btn">发请求</button>

  <script>
    const btn = document.querySelector('.btn')

    function handle() {
      console.log('向后端发请求');
    }

    btn.addEventListener('click', debounce(handle, 1000))

    function debounce(fn, wait) {
      let timer = null
      return function (...args) {
        if (timer) clearTimeout(timer)
        timer = setTimeout(() => {
          fn.apply(this, args)
        }, wait)
      }
    }

  </script>
</body>

</html>